<template>
  <div id="customer-passengers" class="card col-12 px-0 mt-5">
    <nav aria-label="breadcrumb" role="navigation">
      <ol class="breadcrumb pb-0">
        <li class="breadcrumb-item ms-1">
          <router-link to="/h5/customers">企业客户</router-link>
        </li>
        <li class="breadcrumb-item active" aria-current="page">员工信息</li>

        <li class="breadcrumb-item ms-auto me-1">
          <router-link to="/h5/customer/departments">部门信息</router-link>
        </li>
      </ol>
    </nav>
    <template v-if="showSearchForm === false">
      <div class="card-header">
        <!--  <router-link to="/customer" class="btn btn-success ms-auto"
              >新建</router-link> -->
        <button
          type="button"
          class="btn btn-primary float-end"
          @click.stop="showSearchOption()"
        >
          查找
        </button>
      </div>

      <passenger-list :dataList="dataList"></passenger-list>

      <nav id="pagination-box" class="float-end">
        <my-pagination
          name="pagination"
          :row-count="sc.rowCount"
          :page-total="sc.pageTotal"
          :page-no="sc.pageNo"
          @next-page="nextPage"
          @prev-page="prevPage"
          @direct-page="directPage"
        ></my-pagination>
      </nav>
    </template>
    <template v-else>
      <div class="card-body">
        <form>
          <div class="row mb-2">
            <input
              type="textfield"
              class="form-control"
              placeholder="姓名"
              name="sc.name"
              v-model.trim="searchName"
            />
          </div>
          <div class="row mb-2">
            <input
              type="textfield"
              class="form-control"
              placeholder="手机号"
              v-model.trim="mobile"
            />
          </div>
          <div class="row mb-2">
            <my-select-customer
              :customerId.sync="customerId"
              :status="1"
            ></my-select-customer>
          </div>
          <div class="row mb-2">
            <select class="form-select" v-model.number="sc.pageSize">
              <option value="20">20</option>
              <option value="50">50</option>
              <option value="100">100</option>
              <option value="200">200</option>
              <option value="500">500</option>
            </select>
          </div>
          <div class="row mb-2">
            <button type="button" class="btn btn-primary mb-2" @click="search()">
              确定
            </button>
            <button
              type="button"
              class="btn btn-secondary"
              title="清空查找条件"
              @click="reset()"
            >
              重置
            </button>
          </div>
        </form>
      </div>
    </template>

  </div>
</template>

<script>
import { APP_FLIGHT_PATH } from "@/common/common.js";
import { searchPassengers, uploadPassengers } from "@/api/user.js";
import $ from "jquery";
import MyPagination from "@/components/my-pagination_h5.vue";
import MyDatePicker from "@/components/my-datepicker.vue";
import PassengerList from "@/components/list/passenger-list_h5.vue";
import MySelectCustomer from "@/components/my-select2-customer.vue";

export default {
  name: "passengers",
  components: {
    MyPagination,
    MyDatePicker,
    PassengerList,
    MySelectCustomer
  },
  data() {
    return {
      showSearchForm: false,
      dataList: [],

      sc: {
        rowCount: 0,
        pageNo: 1,
        pageSize: 20,
        pageTotal: 0,
      },
      searchName: "",
      mobile: "",
      customerId: -1,
    };
  },
  mounted: function () {
    this.search();
  },
  methods: {
    showErrMsg: function (msg, msgType) {
      this.$store.dispatch("showAlertMsg", {
        errMsg: msg,
        errMsgType: msgType,
      });
    },
    showLoading: function (loadingText) {
      this.$store.commit("showLoading", {
        loading: true,
        loadingText: loadingText,
      });
    },
    hideLoading: function () {
      this.$store.commit("showLoading", { loading: false });
    },
    showSearchOption: function () {
      this.showSearchForm = true;
    },
    search: function () {
      this.showSearchForm = false;
      const params = {
        "sc.pageNo": this.sc.pageNo,
        "sc.pageSize": this.sc.pageSize,
        "sc.name": this.searchName,
        "sc.mobile": this.mobile,
        "sc.customerId": this.customerId,
      };
      // this.showLoading('查询中...')
      searchPassengers(params, (jsonResult) => {
        this.dataList = jsonResult.dataList;
        this.sc = jsonResult.page;
        // this.hideLoading()
      });
    },
    reset: function () {
      this.searchName = "";
      this.sc.pageNo = 1;
      this.search();
    },
    prevPage: function () {
      this.sc.pageNo = this.sc.pageNo - 1;
      if (this.sc.pageNo < 1) this.sc.pageNo = 1;
      this.search();
    },
    nextPage: function () {
      this.sc.pageNo = this.sc.pageNo + 1;
      this.search();
    },
    directPage: function (pageNo) {
      this.sc.pageNo = pageNo;
      this.search();
    },
  },
};
</script>